<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="socnet.controller.*" %>
<%@ page import="socnet.model.*" %>
<%@ page import="java.util.*" %>
<%@ page import="org.neo4j.graphdb.*" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<link href="./login.css" rel="stylesheet" type="text/css" />


<body>

<div class="container">
  <div class="header">
    <h1 ><img src="images/GEEK_small.jpg" alt="Insert Logo Here" float="left name="Insert_logo" width="100" height="100" id="Insert_logo" style="background-color: #8090AB; display:block; float:right;" />
  Welcome at GeekSocNet! </h1> 
<br />

    <!-- end .header --></div>
    
    <%
		if (request.getParameter("Login") != null) {
	//		SocnetController au = new SocnetController();
	//		SocnetDAO au = new SocnetDAO();
	//		au.createDb();
	//		List<User> friends = au.getFriends("bata.andras@gmail.com");
	//		au.shutDown();
	//		Iterator<User> it = friends.iterator();
	//		while(it.hasNext()){
	//			System.out.println(it.next().getName());
	//		} 
					String username = request.getParameter("username");
					String password = request.getParameter("password");
					
					if (username == null || username == "") { 
					%>
					<script type="text/javascript">
						alert("Plz. Enter your user name!");
					</script>
					<%
					} else if (password == null || password == "") {
						%>
						<script type="text/javascript">
							alert("Plz. Enter your password!");
						</script>
						<%
					} else {
						SocnetController soc = new SocnetController();
				//		soc.startDB();
						System.out.println("User: " + username + " Pass: " + password);
						if(SocnetController.checkPassw(username, password)) {
							session.setAttribute("isLogged", Boolean.TRUE);
							session.setAttribute("email", username);
							response.sendRedirect("myPage.jsp");
				//			soc.stopDB();
						} else {
							%>
							<script type="text/javascript">
								alert("Invalid email address or password!");
							</script>
							<%
						}
				//		soc.stopDB();
					}
		}
		%>
    
    <script type="text/javascript">
        function ccheck()
        {
        uid=document.f1.username.value;
        cpass=document.f1.password.value;
        
        if(uid=="" || uid==null)
        {
        alert("Plz. Enter your email address!");
        document.f1.uid.focus();
        return false;
        }
        if(cpass=="" || cpass==null)
        {
        alert("Plz. Enter your password!");
        document.f1.cpass.focus();
        return false;
        }
//        metodushivas
  //      if(true) 
	        session.setAttribute("username",cid);
//	        con.close(); 
	        response.sendRedirect("myPage.jsp");
	        return true;
    //    }
        }
    </script>    
    
  <div class="sidebar1">
      <form action="logInPage.jsp" method="post">
        Email: <br />
        <input name="username" type="text" size="30" maxlength="50" /> <br />
        Password: <br />
        <input name="password" type="password" size="30" maxlength="50" /> <br />
        <input name="Login" type="submit" value="Login" />
        </form>
        <a href="register.jsp" title="Register" target="_self" style="color: #0000FF; font-size: 10pt">Need an account? Sign Up</a>
    <!-- end .sidebar1 --></div>
  <div class="content">
    <h1><img src="images/born-geek.jpg" width="100%" /><!-- end .content --></h1>
  </div>

  <!-- end .container --></div>
</body>
</html>